﻿namespace Microsoft.SharePoint.Client
{
    using System;
    using System.ComponentModel;

    [ScriptType("SP.RoleAssignment", ServerTypeId="{07da03be-4d19-48f3-9c5f-7c67b134a93b}")]
    public class RoleAssignment : ClientObject
    {
        [EditorBrowsable(EditorBrowsableState.Never)]
        public RoleAssignment(ClientRuntimeContext Context, ObjectPath ObjectPath) : base(Context, ObjectPath)
        {
        }

        [Remote]
        public void DeleteObject()
        {
            ClientAction query = new ClientActionInvokeMethod(this, "DeleteObject", null);
            base.Context.AddQuery(query);
            base.RemoveFromParentCollection();
        }

        [Remote]
        public void ImportRoleDefinitionBindings(RoleDefinitionBindingCollection roleDefinitionBindings)
        {
            ClientAction query = new ClientActionInvokeMethod(this, "ImportRoleDefinitionBindings", new object[] { roleDefinitionBindings });
            base.Context.AddQuery(query);
        }

        protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader)
        {
            bool flag = base.InitOnePropertyFromJson(peekedName, reader);
            if (!flag)
            {
                string str = peekedName;
                if (str == null)
                {
                    return flag;
                }
                if (!(str == "Member"))
                {
                    if (str == "RoleDefinitionBindings")
                    {
                        flag = true;
                        reader.ReadName();
                        this.RoleDefinitionBindings.FromJson(reader);
                    }
                    return flag;
                }
                flag = true;
                reader.ReadName();
                this.Member.FromJson(reader);
            }
            return flag;
        }

        [Remote]
        public void Update()
        {
            ClientAction query = new ClientActionInvokeMethod(this, "Update", null);
            base.Context.AddQuery(query);
        }

        [Remote]
        public Principal Member
        {
            get
            {
                object obj2;
                if (base.ObjectData.ClientObjectProperties.TryGetValue("Member", out obj2))
                {
                    return (Principal) obj2;
                }
                Principal principal = new Principal(base.Context, new ObjectPathProperty(base.Context, base.Path, "Member"));
                base.ObjectData.ClientObjectProperties["Member"] = principal;
                return principal;
            }
        }

        [Remote]
        public RoleDefinitionBindingCollection RoleDefinitionBindings
        {
            get
            {
                object obj2;
                if (base.ObjectData.ClientObjectProperties.TryGetValue("RoleDefinitionBindings", out obj2))
                {
                    return (RoleDefinitionBindingCollection) obj2;
                }
                RoleDefinitionBindingCollection bindings = new RoleDefinitionBindingCollection(base.Context, new ObjectPathProperty(base.Context, base.Path, "RoleDefinitionBindings"));
                base.ObjectData.ClientObjectProperties["RoleDefinitionBindings"] = bindings;
                return bindings;
            }
        }
    }
}

